﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ewal.Data;

namespace DefektaiApp
{
    public partial class fRequestIntComboTextText : Form
    {
        public fRequestIntComboTextText(
            string formCaption,
            string mainLabelText,
            string textBoxLabelText,
            string comboBoxLabelText,
            string comboBoxValuesSql)
        {
            InitializeComponent();
            this.Text = formCaption;
            this.lblMain.Text = mainLabelText;
            this.lblTextBox.Text = textBoxLabelText;
            this.lblCombobox.Text = comboBoxLabelText;
            this.cmbCombo.DataSource = DbHelper.FillDataTable(comboBoxValuesSql);
            this.cmbCombo.ValueMember = "valueMember";
            this.cmbCombo.DisplayMember = "displayMember";
            Program.pubString = string.Empty;
            Program.pubInt = -1;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.cmbCombo.SelectedIndex == -1 || string.IsNullOrEmpty(this.txbText.Text.Trim()))
            {
                return;
            }

            try
            {
                Program.pubInt = Convert.ToInt32(this.cmbCombo.SelectedValue);
                Program.pubString = this.txbText.Text.Trim();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch
            {
                MessageBox.Show("Parinkite liniją.");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
